package com.example.mobifin_busticket;

import java.io.File;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import com.example.mobifin_busticket.models.PassengerDetails;
import com.example.mobifin_busticket.models.SeatDetailsModel;
import com.example.mobifin_busticket.models.SourceModel;
import com.example.mobifin_busticket.models.TicketDetailsModel;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Environment;
import android.os.StatFs;
import android.util.Base64;
import android.view.Display;
import android.view.WindowManager;

public class AppData {
	/*************************************************************************************************
	 * Below variables need to get changed at the time of Creation of Build
	 * 
	 * ***********************************************************************************************/
 
	public static UserInfo userinfo;
	public static String sessionID;
	
	public static ArrayList<SourceModel> list;
	public static ArrayList<SeatDetailsModel> SeatList;
	public static ArrayList<String> SeatLayout;
	public static ArrayList<Integer> fareList;
	public static String Source = "SOURCE";
	public static String Destination = "DESTINATION";
	public static String DateOfJourny = "DOJ";
	public static String TravelBoarding = "TravelBoarding";
	public static String BusId = "BusId";
	public static String SourceId = "SourceId";
	public static String DestinationId = "DestinationId";
	public static String BoardingPointId = "BoardingPointId";
	public static String JSONObj = "JSONObj";
	public static PassengerDetails PassengerModel;
	
	// public static String hsm_host="http://qa-m-hsm.panamaxil.com";
	// public static String host="http://qa-m-res.panamaxil.com";
	// public static String product_host="http://qa-m-tws.panamaxil.com";
	// public static String MDM_host = "http://qa-m-mdm.panamaxil.com";

	/*
	 * public static String host="http://qa301-res.panamaxil.com"; public static
	 * String hsm_host="http://qa301-hsm.panamaxil.com"; public static String
	 * product_host="http://qa301-tws.panamaxil.com"; public static String
	 * MDM_host = "http://qa301-mdm.panamaxil.com";
	 */

	// public static String host = "http://aakaradmin.retel.in";
	// public static String hsm_host = "http://hsm.bankaiintelligence.com";
	// public static String product_host =
	// "http://tsadmin.bankaiintelligence.com";
	// public static String MDM_host = "http://mdm.bankaiintelligence.com";

	public static String host = "http://akar-m-res.panamaxil.com";//aa url par data mokaliye che
	public static String hsm_host = "http://bspl-m-hsm.panamaxil.com";
	public static String product_host = "http://bspl-m-tws.panamaxil.com";
	

	// public static String host ="http://aakaradmin.retel.in";
	// public static String hsm_host ="http://hsm.bankaiintelligence.com";
	// public static String product_host
	// ="http://tsadmin.bankaiintelligence.com";
	// public static String MDM_host = "http://mdm.bankaiintelligence.com";

	// public static String host = "http://dev301-res.panamaxil.com";
	// public static String hsm_host = "http://dev301-hsm.panamaxil.com";
	// public static String product_host = "http://dev301-tws.panamaxil.com";
	// public static String MDM_host = "http://qa301-mdm.panamaxil.com";

	// public static String host="http://dev300-res.panamaxil.com";
	// public static String hsm_host="http://dev300-hsm.panamaxil.com";
	// public static String product_host="http://dev300-tws.panamaxil.com";

	// public static String host="http://zprepay-res.panamaxil.com";
	// public static String hsm_host="http://zprepay-hsm.panamaxil.com";
	// public static String product_host="http://zprepay-tws.panamaxil.com";

	public static final String DataBaseName = "MobifinBus.db";

	public static final String DataBaseName_Bus = "mobifinBusTicket.db";

	public static final String AccessType = "0";
	public static final String TerminalType = "001";

	// public static final String Currency="USD";
	public static final String CURRENCY = "INR";

	// public static String BusinessClientTransactionKey= "6121118827"; //QA301
	// India Deployment
	// public static String BusinessClientTransactionKey= "1638127020"; //CNR
	// 301
	// public static String BusinessClientTransactionKey= "1880736703";//Dev301
	public static String BusinessClientTransactionKey = "2079915467"; // Akar
																		// Local

	// public static String BusinessClientTransactionKey = "1434718685"; //
	// AkarRetel

	public static String app_tracking_pattern = "IND/2014/NOV/01/+5:30/Retel/Agent/Android/login/1";

	public static String appPreferenceName = "Mobifin-Agent";

	public static String AppCode = "RETEL-ANDROID-AGENT";
	/*************************************************************************************************/
	public static String terminalNumberHostURL = host
			+ "/commonrest/commonrest";
	public static String productURL = product_host + "/productrest/productrest";
	public static String AgenthostURL = host
			+ "/distributormobilerest/distributormobilerest";
	public static String hsm_hostURL = hsm_host + "/hsmrest/hsmrest";
	public static ArrayList<TicketDetailsModel> ticketDetailsList;
	public static ArrayList<TicketDetailsModel> InventoryList;
	public static int inventoryList;
	public static boolean isAc;
	public static boolean isNonAc;
	public static boolean isNonSleeper;
	public static boolean isSleeper;
	public static ArrayList<String> TravelResult;
	public static ArrayList<String> Boardingresult;
	public static int flag;
	public static ArrayList<String> Dropingresult;
	public static List<String> selectListFilterTravels;
//	public static String AppUpdateURL = MDM_host + "/api/commonapi/";
	public static final String SHOPNAMETERMSEMAIL = "Mobifin";
	public static final String USERNAMEEMAIL = "droid.panamax@gmail.com";
	public static final String PASSWORDEMAIL = "h@panamax";

	// private static final String username = "care@callnroam.com";
	// private static final String password = "care321";
	// public static final String PORTNO = "25";
	// public static final String IPADDRESS = "204.15.169.225";
	public static final String PORTNO = "587"; // Port No for Gmail
	public static final String IPADDRESS = "smtp.gmail.com"; // Host for Gmail
	// SMTP

	// public static final String MESSAGEURL =
	// "http://192.168.2.21:7050/isms.server.php";
	// public static final String LOGINID = "22220549";
	// public static final String LOGINPASSWORD = "JW39m953z5Y34bMO";
	// public static final String TYPE = "isms";
	// public static final String CONTEXT = "Dummy";
	public static final String MESSAGEURL = "http://103.16.101.52:8080/bulksms/bulksms?";
	public static final String LOGINID = "bisp-aakar_m";
	public static final String LOGINPASSWORD = "12345678";
	public static final String SMSTYPE = "0";
	public static final String TYPE = "isms";
	public static final String SOURCENAMESMS = "ReteLM";

	public static final String CONTEXT = "Routesms";

	// public static String
	// HSMRestURL="http://192.168.2.21:5026/hsmrest/hsmrest";
	/*
	 * public static String
	 * terminalNumberhost="http://pynt-m-res.panamaxil.com"; public static
	 * String terminalNumberHostURL=terminalNumberhost+"/commonrest/commonrest";
	 * public static String
	 * productURL="http://pynt-m-tws.panamaxil.com/productrest/productrest";
	 * public static String AgenthostURL=terminalNumberhost+
	 * "/distributormobilerest/distributormobilerest";
	 */

	// Busticketing Constatnts
	public static final String APPLICATION_VERSION_TRACKER = "Application_Version_Tracker";
	public static final String CLIENT = "Client";

	public static final String EXCEPTION = "EXCEPTION";
	public static final String ENABLED = "Enabled";
	public static final String TRANSACTIONPIN = "Transaction PIN";
	public static final String UPDATEAPP = "UPDATE_APP";
	public static final String DEBUG = "DEBUG";

	public static final int HSMFLAG = 1;
	public static final int TERMINALKEYFLAG = 0;
	public static final int COMMANFLAG = 2;
	public static final int TESTFLAG = 3;
	public static final String CONSUMERKEY = "vLrlKnO7XgdH3eu4dvcG5BU9QwCtrQ";
	public static final String SECRETKEY = "AdsphqRmHTvhtZLyiNoCeliLJP2NXZ";
	public static final String BASESEATURL = "http://api.seatseller.travel";

	public static final String SOURCEPASSSTRING = "sources";
	public static final String GETBLOCKKEY = "blockTicket";

	public static final String SOURCEPASSSTRINGDEST = "source";

	public static final String DOJ = "doj";
	public static final String REPONSE200 = "200";
	public static final String ERROR500 = "500";
	public static final String ERROR504 = "504";
	public static final String ERRORMINUS1 = "-1";
	public static final String ERROR0 = "0";
	public static final String ERROR = "error";

	public static final String INTERNELERROR = "Sorry, seems something Went wrong! Try again after some time";
	public static final String INTERNELCANCELERROR = "Sorry, Ticket is not Cancellable!";
	public static final String NULLEROORAVAITRIP = "Sorry but we do not have any buses on this route";
	public static final String NULLEROORTRIPDETAIL = "Sorry Trip details not available for this bus";
	public static final String NULLEROORCANCELATIONDATA = "No Ticket Found";
	public static final String NULLEROORTICKETDETAIL = "Ticket details not found for given pin";

	public static final String FILTERBYTRAVELS = "Filter by travels";
	public static final String FILTERBYBOARDINGPOINTS = "Filter by boarding points";
	public static final String FILTERBYDROPPINGPOINTS = "Filter by dropping points";
	public static final String DYNAMICVALUE = "DynamicValue";
	public static final String DESTINATIONPASSSTRING = "destinations";
	public static final String CITYLIST = "CITYLIST";
	public static final String TAG = "TAG";
	public static final String SOURCENAME = "SOURCENAME";
	public static final String SOURCEID = "SOURCEID";
	public static final String DESTINATIONID = "DESTINATIONID";
	public static final String BPOINTID = "bpointID";
	public static final String DEPARTTIMEFORSUMMARY = "departTimeforSummary";
	public static final String SOURCE = "source";

	public static final String BLOCKKEY = "blockKey";

	public static final String AVAILABLETRIPS = "availabletrips";
	public static final String TRIPDETAILS = "tripdetails";
	public static final String DESTINATION = "destination";
	public static final String DESTINATIONNAME = "DESTINATIONNAME";

	public static final String LOWERSEAT = "Lower";
	public static final String UPPERSEAT = "Upper";
	public static final String LADIESSEAT = "LadiesSeat";

	public static final String UPPERLOWERSEAT = "UpperLower";
	public static final String SRCDESTNAMDOJ = "srcDestnamDoj";
	public static final String TRAVELNAMETIME = "travelNameTime";
	public static final String TOTALFARE = "TOTALFARE";
	public static final String TOTALSEAT = "TOTALSEAT";

	public static final String EMAILID = "EMAILID";
	public static final String NOTES = "NOTES";
	public static final String PHONENO = "PHONENO";

	public static final String NODATA = "Error so that prevent Data to be enter in database";
	public static final String BLANKSTRING = "";
	public static final String MR = "Mr.";
	public static final String MS = "Ms.";
	public static final String RADIOTAG = "RADIOTAG";
	public static final String EDITTEXTTRAVELTAG = "EDITTEXTTRAVELTAG";
	public static final String EDITTEXTAGETAG = "EDITTEXTAGETAG";
	public static final String TEXTVIEWTAG = "TEXTVIEWRAG";
	public static final String SPTITLETAG = "SPTITLETAG";
	public static final String PASSENGERDETAIL = "PASSENGERDETAIL";
	public static final String BLOCKREQOBJ = "BLOCKREQOBJ";
	public static final String TICKETDETAILSUMMARY = "TICKETDETAILSUMMARY";
	public static final String CANCELTICKETDETAIL = "CANCELTICKETDETAIL";
	public static final String CANCELLATIONDATA = "cancellationdata";
	public static final String TIN = "tin";
	public static final String BOOKTICKET = "bookticket";
	public static final String TICKET = "ticket";
	public static final String BLOCKKEYPOST = "blockKey";
	public static final String AUTHORIZEKEY = "AuthorizeKey";
	public static final String SUMMARYBACK = "Summaryback";
	public static final String BOOKINGMETHOD = "Booking";
	public static final String BOOKINGREFUNDMETHOD = "BookingRefund";
	public static final String BOOKINGUPDATEMETHOD = "BookingUpdateInfo";

	public static final String CANCELTICKET = "cancelticket";
	public static final String CANCELLED = "CANCELLED";
	public static final String CANCELLATIONSUB = "Cancellation";
	public static final String BOOKINGSUB = "Booking";
	public static final String SUMMARYSCREEN = "SummaryScreen";
	public static final String PRINTSCREEN = "PrintScreen";

	public static final String SEATTOCANCEL = "seatsToCancel";
	public static final String CANCELLATIONCHARGES = "cancellationcharges";
	public static final String CANCELLATIONFARES = "cancellationfares";
	public static final String FALSE = "false";
	public static final String TRUE = "true";
	public static final String CLASSNAME = "classname";
	public static final String SEARCHBUSESACTIVITY = "SearchBusesActivity";
	public static final String SELECTSEATBORDINGINFO = "SelectSeatBordinginfo";
	public static final String CONTACTDETAILSACTIVITY = "ContactDetailsActivity";
	public static final String PINCONFORMACTIVITY = "PinConformActivity";
	public static final String PNR = "Pnr";
	public static final String REFUNDAMOUNT = "RefundAmount";
	public static final String TOTALAMOUNT = "TotalAmount";
	public static final String DEPTTIME = "Depttime";
	public static final String STATUS = "Status";
	public static final String REFUNDBOOKING = "RefundBooking";
	public static final String REFUNDBOOKINGCANCEL = "RefundBookingCancel";

	public static final String TRAVELCONTACTNO = "Travelcontactno";
	public static final String FEMALE = "Female";
	public static final String MALE = "Male";

	public static final String MOBILENUMBER = "MobileNumber";
	public static final String REQUESTID = "RequestID";
	public static final String SUBJECT = "SUBJECT";
	public static final String MESSAGE = "MESSAGE";
	public static final String SMSBODY = "SMSBODY";
	public static final String ISPARTIALCANCEL = "ISPARTIALCANCEL";

	public static String getCurrentTime() {
		SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyyHHmmssSSS");
		Date now = new Date();
		String strdate = sdf.format(now);
		System.out.println("current date is " + strdate);
		return strdate;
	}

	// format bid double value in two decimal form
	public static String roundTwoDecimals(double d) {
		DecimalFormat twoDForm = new DecimalFormat("#.##");
		return new BigDecimal(twoDForm.format(d)).toPlainString();
	}

	public static String getAppCurrentVersion(Context mctx) {
		String version = null;
		try {
			PackageInfo pInfo = mctx.getPackageManager().getPackageInfo(
					mctx.getPackageName(), 0);
			version = pInfo.versionName;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		return version;
	}

	public static String getAppCurrentVersionCode(Context mctx) {
		int version = 0;
		try {
			PackageInfo pInfo = mctx.getPackageManager().getPackageInfo(
					mctx.getPackageName(), 0);
			version = pInfo.versionCode;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		return String.valueOf(version);
	}

	public static boolean externalMemoryAvailable() {
		return android.os.Environment.getExternalStorageState().equals(
				android.os.Environment.MEDIA_MOUNTED);
	}

	public static long getAvailableExternalMemorySize() {
		if (externalMemoryAvailable()) {
			File path = Environment.getExternalStorageDirectory();
			StatFs stat = new StatFs(path.getPath());
			long blockSize = stat.getBlockSize();
			long availableBlocks = stat.getAvailableBlocks();
			return ((availableBlocks * blockSize) / 1024);
		} else {
			return 0;
		}
	}

	public static boolean isInputValid(String email, String stringPattern) {
		boolean isValid = false;

		String expression = stringPattern;

		byte[] base64Decrypted = Base64.decode(expression.getBytes(),
				Base64.DEFAULT);
		String decrypted = new String(base64Decrypted);
		String newPattern = decrypted.substring(1, decrypted.length() - 1);// remove
																			// "/"
																			// from
																			// first
																			// and
																			// last
																			// index

		CharSequence inputStr = email;

		System.out.print(" &&&&&&&&****** Decrypted Reg Ex===>" + newPattern);
		try {
			Pattern pattern = Pattern.compile(newPattern, Pattern.MULTILINE
					| Pattern.CASE_INSENSITIVE);
			Matcher matcher = pattern.matcher(inputStr);
			if (matcher.matches()) {
				isValid = true;
			}
		} catch (PatternSyntaxException e) {
			System.out.println(e.toString());
			e.printStackTrace();
			// Toast.makeText(, text, duration)
		}

		return isValid;
	}

	public static String mRetrieveDeviceInfo(Context ctx) {
		String clientInfo = "";
		try {
			WindowManager wm = (WindowManager) ctx
					.getSystemService(Context.WINDOW_SERVICE);
			Display display = wm.getDefaultDisplay();
			clientInfo = "Android" + "," + "," + android.os.Build.MODEL + ","
					+ android.os.Build.ID + "," + display.getWidth() + "x"
					+ display.getHeight() + "," + android.os.Build.MANUFACTURER
					+ "," + android.os.Build.BOARD + ","
					+ android.os.Build.DISPLAY + ","
					+ android.os.Build.FINGERPRINT;
		} catch (Exception e) {
			clientInfo = "";
		}

		return clientInfo;
	}
	public static UserInfo getUserInfo() {
		// TODO Auto-generated method stub
		return userinfo;
	}
	public static void setUserInfo(UserInfo u) {
		// TODO Auto-generated method stub
		userinfo=u;
	}

	public static void setSessionId(String sID) {
		// TODO Auto-generated method stub
		sessionID=sID;
	}
	public static String getSessionId(){
		return sessionID;
	}
}